<?php
namespace app\model;
use app\BaseModel;
use think\model\concern\SoftDelete;
use app\model\Depart;
use app\model\WorkerType;

class Worker extends BaseModel
{

    use SoftDelete;
    protected $deleteTime = 'delete_time';
    protected $defaultSoftDelete = '0000-00-00 00:00:00';
    protected $hidden = ['update_time','delete_time','sort','status'];

    public function searchTitleAttr($query,$value,$data){
        if(!empty($value)){
            $query->where('mobile','like','%'.$value.'%');
        }
    }
    public function searchCompanyIdAttr($query,$value,$data){
        if(!empty($value)){
            $query->where('company_id','=',$value);
        }
    }
    public function searchDepartIdAttr($query,$value,$data){
        if(!empty($value)){
            $query->where('depart_id','=',$value);
        }
    }
    public function searchWorkerTypeIdAttr($query,$value,$data){
        if(!empty($value)){
            $query->where('worker_type_id','=',$value);
        }
    }



    protected function setDepartIdAttr($value,$data){ //当前字段的修改器
         $this->set('depart_title',Depart::where('id',$value)->value('title'));
         return $value;
    }
    protected function setWorkerTypeIdAttr($value,$data){ //当前字段的修改器
         $this->set('worker_type_title',WorkerType::where('id',$value)->value('title'));
         return $value;
    }

    protected function setCompanyIdAttr($value,$data){ //当前字段的修改器
        $this->set('company_title',Company::where('id',$value)->value('title'));
        return $value;
    }



}